package com.zhangye.test.api;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhangye.test.model.ProxyAr;
import com.zhangye.test.model.ProxyScanCount;
import com.zhangye.test.service.ProxyArService;
import com.zhangye.test.service.ProxyScanCountService;

@Controller
@RequestMapping("api/proxyScanCount")
public class ProxyScanCountApi {
	
	@Autowired
	private ProxyArService proxyArService;
	@Autowired
	private ProxyScanCountService proxyScanCountService;
	

	@ResponseBody
	@RequestMapping(value = "/insert")
	public ApiResult getName(String videoUrl) {
		ApiResult result = new ApiResult();
		if(videoUrl != null && !"".equals(videoUrl)){
			List<ProxyAr> list = proxyArService.selectByWhere(" and video_url = '" + videoUrl + "'");
			if(list.size() > 0){
				ProxyScanCount psc = new ProxyScanCount();
				psc.setVideoUrl(videoUrl);
				psc.setImageUrl(list.get(0).getImageUrl());
				psc.setAddress("石家庄");
				psc.setPhoneType("iphone7");
				psc.setCreatedAt(new Date());
				int count = proxyScanCountService.insert(psc);
				if(count > 0){
					result.msg.status = 0;
					result.msg.desc = "添加成功";
				}else{
					result.msg.status = 1;
					result.msg.desc = "系统错误，添加失败";
				}
			}else{
				result.msg.status = 4;
				result.msg.desc = "暂无数据，添加失败";
			}
		}else{
			result.msg.status = 3;
			result.msg.desc = "参数不能为空";
		}
		return result;
	}

}
